package com.jeecms.wicool.dao.product.impl;


import org.springframework.stereotype.Repository;

import com.jeecms.common.hibernate3.Finder;
import com.jeecms.common.hibernate3.HibernateBaseDao;
import com.jeecms.common.page.Pagination;
import com.jeecms.wicool.dao.product.ProductRelationDao;
import com.jeecms.wicool.entity.product.ProductRelation;

@Repository
public class ProductRelationDaoImpl extends HibernateBaseDao<ProductRelation, Integer>
		implements ProductRelationDao {

	@Override
	protected Class<ProductRelation> getEntityClass() {
		// TODO Auto-generated method stub
		return ProductRelation.class;
	}
	@Override
	public Pagination getPage(Integer productId, int pageNo, int pageSize) {
			Finder f = Finder.create("select bean from ProductRelation bean where 1=1 ");
			
			if (null!=productId){
				f.append(" and bean.product.id = :productId");
				f.setParam("productId",productId);
			}
			f.append(" order by bean.id desc");
			return find(f, pageNo, pageSize);
	}
	@Override
	public ProductRelation findById(Integer id) {
		ProductRelation entity = get(id);
		return entity;
	}
	@Override
	public ProductRelation save(ProductRelation bean) {
		getSession().save(bean);
		return bean;
	}
	@Override
	public ProductRelation deleteById(Integer id) {
		ProductRelation entity = super.get(id);
		if (entity != null) {
			getSession().delete(entity);
		}
		return entity;
	}
}